package com.exam.lenovo;

import java.util.Scanner;

/**
 * date:
 * description:
 */
public class Solution02 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int q = scanner.nextInt();
        int[][] matrix = new int[n][n];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                matrix[i][j] = scanner.nextInt();
            }
        }
        for (int i = 0; i < q; i++) {
            int type = scanner.nextInt();
            int index = scanner.nextInt() - 1;
            if(type == 1) {
                int tmp = matrix[index][n - 1];
                for (int j = n - 1; j > 0; j--) {
                    matrix[index][j] = matrix[index][j - 1];
                }
                matrix[index][0] = tmp;
            } else {
                int tmp = matrix[0][index];
                for (int j = 0; j < n - 1; j++) {
                    matrix[j][index] = matrix[j + 1][index];
                }
                matrix[n - 1][index] = tmp;
            }
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                System.out.print(matrix[i][j] + " ");
            }
            System.out.println();
        }
    }
}
